<template>
  <div class="container">
    <card title="产品分类">
      <div class="asm-table">
        <div class="asm-tr">
          <div class="asm-th asm-grow-1">序号</div>
          <div class="asm-th">分类</div>
          <div class="asm-th">操作</div>
        </div>
        <div class="asm-tr" v-if="isLoading">
          <loading></loading>
        </div>
        <div class="asm-tr asm-no-data" v-else-if="list.length < 1"></div>
        <div class="asm-tr" v-for="(item, index) in list" v-else>
          <div class="asm-th asm-grow-1">{{index + 1}}</div>
          <div class="asm-th">
            <div class="app">
              <div class="app-img"><img :src="item.item_pic"/></div>
              <div class="app-name">{{item.item_name}}</div>
            </div>
          </div>
          <div class="asm-th"><a @click="showSort(item.id)">分类管理</a></div>
        </div>
      </div>
    </card>
    <modal ref="sort" :visible="false">
      <sort :id="id" :ads="ads" @close="closeSort"></sort>
    </modal>
  </div>
</template>
<script>
import { Modal } from '@/components/Modal'
import Sort from './sort'
export default {
  name: 'category',
  components: {
    Modal,
    Sort
  },
  created () {
    let param = {
      page: 1,
      per_page: 10000,
      terminal_type: 'ios'
    }
    this.isLoading = true
    Promise.all([
      this.$api.get('ads/ad_item'),
      this.$api.get('ads', param)
    ]).then(req => {
      this.list = req[0]
      this.ads = req[1].list
      this.isLoading = false
    })
  },
  data () {
    return {
      isLoading: false,
      list: [],
      ads: [],
      id: 1
    }
  },
  methods: {
    showSort (id) {
      this.id = id
      this.$nextTick(() => {
        this.$refs.sort.open()
      })
    },
    closeSort () {
      this.$refs.sort.close()
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/scss/table.scss';
.asm-th{
  .app {
    display: flex;
    flex-direction: column;
    align-items: center;
    .app-img {
      img {
        width: 40px;
      }
    }
  }
}
</style>


